/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 *  \file     Sent.h                                                                                    *
 *  \brief    This file contains interface header for Sent MCAL driver                                  *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2024/10/30     <td>1.0.0                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifndef SENT_H
#define SENT_H
/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "Sent_Types.h"
#include "Sent_Ip.h"
#include "Sent_Cfg.h"
#include "Std_Types.h"

/**
 *
 * \defgroup MCAL_SENT SENT Driver API
 *
 * The SENT Driver MCAL provides low level access to SENT peripheral
 *
 * \sa SENT_CFG
 * \sa SENT_API
 * \sa SENT_MACRO
 * \{
 */

/**
 *  \defgroup SENT_CFG SENT Configuration.
 *
 * This files defines SENT MCAL configuration structures
 *  \{
 */

/** \} */

/**
 *  \defgroup SENT_API SENT Api.
 *
 * This files defines SENT MCAL api
 *  \{
 */

/** \} */

/**
 *  \defgroup SENT_MACRO SENT macro.
 *
 * This files defines SENT MCAL macro
 *  \{
 */

/** \} */

/**
 *  \addtogroup SENT_API SENT Api.
 *  \{
 */
/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
#if (STD_ON == SENT_TIME_STAMP_FUNCTION)
/** *****************************************************************************************************
 * \brief The time stamp function is initialised.
 *
 * \verbatim
 * Syntax             : void Sent_TimeStampInit(Sent_TimeStampChannelType channelId,
 *                              const Sent_TimeStampCfgType * timeStampCfg)
 *
 * Service ID[hex]    : 0x00
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *                      timeStampCfg - EB configured time stamp configuration
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : The time stamp function is initialised.
 * \endverbatim
 *******************************************************************************************************/
void Sent_TimeStampInit(Sent_TimeStampChannelType channelId,
                        const Sent_TimeStampCfgType *timeStampCfg);

/** *****************************************************************************************************
 * \brief Locking time stamp register value.
 *
 * \verbatim
 * Syntax             : void Sent_TimeStampLatch(Sent_TimeStampChannelType channelId,
 *                                      Sent_Ip_TimeStampOpType operation)
 *
 * Service ID[hex]    : 0x01
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *                      operation - latch lock register or unlatch lock register
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Locks the time stamp register value. It only locks the
 *                          registers, the real counter is still running all the time.
 * \endverbatim
 *******************************************************************************************************/
void Sent_TimeStampLatch(Sent_TimeStampChannelType channelId, Sent_Ip_TimeStampOpType operation);

/** *****************************************************************************************************
 * \brief Clear timestamp counter.
 *
 * \verbatim
 * Syntax             : void Sent_TimeStampCntClr(Sent_TimeStampChannelType channelId)
 *
 * Service ID[hex]    : 0x02
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Clears the timestamp counter and the register runs from 0.
 * \endverbatim
 *******************************************************************************************************/
void Sent_TimeStampCntClr(Sent_TimeStampChannelType channelId);

/** *****************************************************************************************************
 * \brief Gets the timestamp counter.
 *
 * \verbatim
 * Syntax             : Sent_TimeStampValueType Sent_TimeStampGet
 *                                      (Sent_TimeStampChannelType channelId)
 *
 * Service ID[hex]    : 0x03
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - time stamp Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : time stamp val
 *
 * Return value       : None
 *
 * Description        : Gets the timestamp counter.
 * \endverbatim
 *******************************************************************************************************/
Sent_TimeStampValueType Sent_TimeStampGet(Sent_TimeStampChannelType channelId);
#endif /** #if (STD_ON == SENT_TIME_STAMP_FUNCTION) */

/** *****************************************************************************************************
 * \brief Channel function initialisation.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelInit(Sent_ChannelType channelId,
 *                                          const Sent_ChannelCfgType * ConfigPtr)
 *
 * Service ID[hex]    : 0x04
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *                      ConfigPtr - Configuration parameters for EB configuration.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Channel function initialisation.
 * \endverbatim
 *******************************************************************************************************/
void Sent_ChannelInit(Sent_ChannelType channelId, const Sent_ChannelCfgType *ConfigPtr);

/** *****************************************************************************************************
 * \brief Channel deinit function.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelDeInit(Sent_ChannelType channelId)
 *
 * Service ID[hex]    : 0x05
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Channel deinit function.
 * \endverbatim
 *******************************************************************************************************/
void Sent_ChannelDeInit(Sent_ChannelType channelId);

/** *****************************************************************************************************
 * \brief Read nibble frame data.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelReadData(Sent_ChannelType channelId,
 *                                              Sent_Ip_NibDataType *nibbleData)
 *
 * Service ID[hex]    : 0x06
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : nibbleData - nibble data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Read nibble frame data.
 * \endverbatim
 *******************************************************************************************************/
void Sent_ChannelReadData(Sent_ChannelType channelId, Sent_Ip_NibDataType *nibbleData);

/** *****************************************************************************************************
 * \brief Read serial frame data.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelReadSerialData(Sent_ChannelType channelId,
 *                                                  Sent_Ip_SerDataType *serialData);
 *
 * Service ID[hex]    : 0x07
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : serialData - serial data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Read serial frame data.
 * \endverbatim
 *******************************************************************************************************/
void Sent_ChannelReadSerialData(Sent_ChannelType channelId, Sent_Ip_SerDataType *serialData);

#if (STD_ON == SENT_VERSION_INFO_API)
/** *****************************************************************************************************
 * \brief This service returns the version information of this module.
 *
 * \verbatim
 * Syntax             : void Sent_GetVersionInfo(Std_VersionInfoType*
 *                                                          VersionInfoPtr)
 *
 * Service ID[hex]    : 0x08
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : VersionInfoPtr - Pointer to where to store the version
 *                        information of this module
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Returns the version information of this module
 * \endverbatim
 *******************************************************************************************************/
void Sent_GetVersionInfo(Std_VersionInfoType *VerInfoPtr);
#endif /** #if (STD_ON == SENT_VERSION_INFO_API) */


/** *****************************************************************************************************
 * \brief Actual Calculation Result of Tick Period
 *
 * \verbatim
 * Syntax             : Sent_ChannelActualTickType Sent_ChannelActualTick(Sent_ChannelType channelId)
 *
 * Service ID[hex]    : 0x09
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Actual Calculation Result of Tick Period
 * \endverbatim
 *******************************************************************************************************/
Sent_ChannelActualTickType Sent_ChannelActualTick(Sent_ChannelType channelId);

/** *****************************************************************************************************
 * \brief Actual Calculation Result of Tick Period
 *
 * \verbatim
 * Syntax             : void Sent_ChannelUpdateTick(Sent_ChannelType channelId, uint32 div,
 *                              uint32 tick, boolean clrFifo)
 *
 * Service ID[hex]    : 0x0a
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant (but not for the same sent channel)
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *                      preDiv - crossover factor
 *                      tick - tick counter
 *                      clrFifo - Whether or not the fifo needs to be cleared
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Actual Calculation Result of Tick Period
 *                      SentTick(us) = (1 / (RootClk(Mhz) / preDiv)) * tick
 * \endverbatim
 *******************************************************************************************************/
void Sent_ChannelUpdateTick(Sent_ChannelType channelId, uint32 preDiv, uint32 tick,
                            boolean clrFifo);
/** \} */
/** \} */

/** *****************************************************************************************************
 * \brief IRQ handler.Callback function for handling all interrupts into the corresponding channel.
 *
 * \verbatim
 * Syntax             : void Sent_IrqHandler(uint32 base)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non-Reentrant
 *
 * Parameters (in)    : base - sent base address
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : IRQ handler.Callback function for handling all interrupts into the corresponding channel.
 * \endverbatim
 *******************************************************************************************************/
void Sent_IrqHandler(uint32 base);

#if (STD_ON == SENT_DMA_WATER_LEVEL)
/** *****************************************************************************************************
 * \brief Get DMA data interface.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelDmaReadData(Sent_ChannelType channelId,
 *                                              Sent_Ip_NibDataType *nibbleData)
 *
 * Service ID[hex]    : 0x0b
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None - Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : nibbleData - nibble data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Get DMA data interface.
 *******************************************************************************************************/
void Sent_ChannelDmaReadData(Sent_ChannelType channelId, Sent_Ip_NibDataType *nibbleData);

/** *****************************************************************************************************
 * \brief Get DMA data interface.
 *
 * \verbatim
 * Syntax             : void Sent_ChannelDmaReadSerialData(Sent_ChannelType channelId,
 *                                                              Sent_Ip_SerDataType *SerialData)
 *
 * Service ID[hex]    : 0x0c
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None - Reentrant
 *
 * Parameters (in)    : channelId - sent channel Number of channels
 *
 * Parameters (inout) : SerialData - serial data point
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Get DMA data interface.
 *******************************************************************************************************/
void Sent_ChannelDmaReadSerialData(Sent_ChannelType channelId, Sent_Ip_SerDataType *SerialData);
#endif /** #if (STD_ON == SENT_DMA_WATER_LEVEL) */

#endif /* SENT_H */
/* End of file */
